package com.example.springbootrabbitmq.controller;

import com.example.springbootrabbitmq.callback.CallbackSender;
import com.example.springbootrabbitmq.demo2exchangefanout.FanoutSender;
import com.example.springbootrabbitmq.demo1hello.HelloSender1;
import com.example.springbootrabbitmq.demo1hello.HelloSender2;
import com.example.springbootrabbitmq.demo3exchangetopic.TopicSender;
import com.example.springbootrabbitmq.demo1.UserSender;
import com.example.springbootrabbitmq.demo4exchangedirect.DirectSender;
import com.example.springbootrabbitmq.demo6priority.PriorityMsgSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rabbit")
public class RabbitTestController {

    @Autowired
    private HelloSender1 helloSender1;

    @Autowired
    private HelloSender2 helloSender2;

    @Autowired
    private UserSender userSender;

    @Autowired
    private TopicSender topicSender;

    @Autowired
    private FanoutSender fanoutSender;

    @Autowired
    private DirectSender directSender;
    //@Autowired
    //private DelayQueueSender delayQueueSender;

    @Autowired
    private PriorityMsgSender priorityMsgSender;

    @Autowired
    private CallbackSender callbackSender;

    @GetMapping("/hello")
    public String hello() {

        //Servlet servlet = null;

        int size = 10;
        for (int i = 0; i < size; i++) {
            helloSender1.send("hello-"+i);
        }
        return "helloSender1, size = "+size;
    }

    @GetMapping("/oneToMany")
    public String oneToMany() {
        int size = 10;
        for (int i = 0; i < 10; i++) {
            helloSender1.send("hellomsg-" + i);
        }
        return "helloSender1, size = "+size;
    }

    @GetMapping("/manyToMany")
    public String manyToMany() {
        int size = 10;
        for (int i = 0; i < size; i++) {
            helloSender1.send("helloSender1-msg-" + i);
            helloSender2.send("helloSender2-msg-" + i);
        }
        return "helloSender1,helloSender1: size = "+size;
    }

    @GetMapping("/userTest")
    public String userTest() {
        userSender.send();
        return "userSender";
    }

    @GetMapping("/topicTest")
    public String topicTest() {
        topicSender.send();
        return "topicSender";
    }

    @GetMapping("/fanoutTest")
    public String fanoutTest() {
        fanoutSender.send();
        return "fanoutSender";
    }

    @GetMapping("/directTest")
    public String directTest() {
        directSender.send();
        return "directSender";
    }

    @GetMapping("/delayTest")
    public String delayTest() {
        //delayQueueSender.send();
        return "delayQueueSender";
    }

    @GetMapping("/callback")
    public String callback() {
        callbackSender.send();
        return "callbackSender";
    }

    @GetMapping("/priorTest")
    public String priorTest() {
        priorityMsgSender.send();
        return "priorTest";
    }
}
